package com.oto.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import org.springframework.stereotype.Service;

import com.oto.model.SharedDataDO;


/**
 * @author xueqiang.mi
 * @since 2010-12-19
 */
@Service
public class SharedDataService extends BaseService {

	public void add(SharedDataDO sd) {
		Date now = new Date();
		sd.setCrtDate(now);

		save(sd);
	}

	public SharedDataDO get(Long id) {
		return get(SharedDataDO.class, id);
	}

	@SuppressWarnings("unchecked")
	public List<SharedDataDO> lattest() {
		PersistenceManager pm = PMF.get();
		try {
			Query query = pm.newQuery(SharedDataDO.class);
			query.setOrdering("crtDate desc");
			query.setRange(0, 30);
			Collection<SharedDataDO> c = pm.detachCopyAll((Collection<SharedDataDO>) query.execute());
			return new ArrayList<SharedDataDO>(c);
		} finally {
			pm.close();
		}
	}
}
